home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
LOGIC Apps
/
Logic-APPLE_II_APPS.iso
/
mac
/
LOGIC Apple II 5.25" Library - DOS Part 2
/
DOS039.dsk
/
FAST FOURIER TRANSFORM.bas
< prev
next >
Wrap
BASIC Source File
|
2012-02-16
|
3KB
|
105 lines
5 HOME : GOSUB 1500
10 HOME : VTAB 10
20 HIMEM: 16384
50 PRINT "LINES 100 THRU 400 ARE RESERVED FOR GENERATING REAL FR(X) AND IMAGINARY FI(N) DISCRETE SAMPLES OF THE FUNCTION TO BE TRANSFORMED"
60 PRINT "THE NUMBER OF SAMPLES N, MUST BE SOME POWER K, OF 2 E.G. N=16, K=4. A 16 POINT SINE FUNCTION IS CURRENTLY STORED"
100 DIM FR(17),FI(17)
110 FOR N = 1 TO 16:T = .375 *(N -1):FR(N) = EXP( -T) * SIN(T):FI(N) = 0: NEXT N
120 K = 4:N = 16
490 VTAB 19
500 PRINT "DO YOU WANT A LISTING OF THE GENERATED TIME FUNCTION?"
510 INPUT A$
520 IF A$ = "NO" THEN 670
530 IF A$ < >"YES" THEN 500
540 B = FR(1)
550 FOR Z = 2 TO N
560 IF ABS(FR(Z)) >B THEN B = ABS(FR(Z))
580 NEXT Z
590 HGR2 : HCOLOR= 7
600 FOR Z = 1 TO N
610 HPLOT Z *(250/N),90 *(1 -.95 *FR(Z)/B)
620 NEXT Z
665 FOR V = 1 TO 4000: NEXT V
670 TEXT : HOME : VTAB 12
675 PRINT " ---FFT CALCULATION IN PROGRESS---"
710 N = 2 ^K:MR = 0:NN = N -1
720 FOR M = 1 TO NN:L = N
730 L = L/2: IF MR +L >NN THEN 730
735 MR = MR - INT(MR/L) *L +L: IF MR < = M THEN 751
740 TR = FR(M +1):FR(M +1) = FR(MR +1):FR(MR +1) = TR:TI = FI(M +1):FI(M +1) = FI(MR +1):FI(MR +1) = TI: NEXT M
751 L = 1
755 IF L > = N THEN 880
756 ITEP = 2 *L:EL = 1/L
760 FOR M = 1 TO L:A = 3.14159265 *(1 -M) *EL:WR = COS(A):WI = SIN(A)
770 FOR I = M TO N STEP ITEP:J = I +L:TR = WR *FR(J) -WI *FI(J):TI = WR *FI(J) +FR(J):FR(J) = FR(I) -TR:FI(J) = FI(I) -TI:FR(I) = FR(I) +TR:FI(I) = FI(I) +TI
775 NEXT I,M
780 L = ITEP: GOTO 755
880 REM --OUTPUT RESULTS--
885 HOME : VTAB 10
890 PRINT "IN WHAT FORM DO YOU WANT THE OUTPUT?"
900 PRINT "MAGNITUDE SPECTRUM PLOT (!)"
910 PRINT " TABLE OF VALUES (2)"
920 INPUT A
930 IF A = 1 THEN 970
940 IF A = 2 THEN 1130
950 PRINT "INCORRECT INPUT (1 0R "": GOTO 890
960 REM --OUTPUT MAGNITUDE SPECTRUM PLOT--
970 B = 0
975 PRINT " ---CALCULATIONS IN PROGRESS---"
980 FOR Z = 1 TO 1 +N/2
990 X3 = SQR(FR(Z) ^2 +FI(Z) ^2)
1000 IF X3 >B THEN B = X3
1010 NEXT Z
1020 FOR Z = 1 TO 1 +N/2
1025 X = Z
1030 X3 = SQR(FR(Z) ^2 +FI(Z) ^2)
1040 X4 = INT(35 *X3/B)
1050 C = 0
1060 PRINT Z; TAB( 5);"!";
1070 C = C +1
1080 IF C <X4 THEN PRINT "=";: GOTO 1070
1090 PRINT ""
1100 NEXT Z
1110 GOTO 1240
1115 TEXT
1120 REM --OUTPUT TABLE OF VALUES
1130 U = 1:Z = 1
1145 TEXT
1150 PRINT "HARM"; TAB( 7);"REAL"; TAB( 18);
1160 PRINT "IMAGINARY"; TAB( 31);"MAGNITUDE"
1170 X3 = SQR(FR(U) ^2 +FI(U) ^2)
1180 PRINT U; TAB( 4);FR(U); TAB( 18);FI(U); TAB( 31);X3
1190 U = U +1:Z = Z +1
1210 IF U >1 +N/2 THEN 1240
1220 GOTO 1170
1230 REM -TERMINATE?-
1240 PRINT "DO YOU WANT ANOTHER OUTPUT (YES,NO)"
1250 INPUT A$
1260 IF A$ = "YES" THEN 890
1270 IF A$ < >"NO" THEN 1240
1280 END
1290 REM --SCRAMBLER ROUTINE--
1300 Y = 0:N1 = N
1310 FOR W = 1 TO L
1320 N1 = N1/2
1330 IF N <N1 THEN 1360
1340 Y = Y +2 ^(W -1)
1350 X = X -N1
1360 NEXT W
1370 RETURN
1380 REM - MAGNITUDE X(3) SUBROUTINE--
1390 GOSUB 1300
1400 X3 = SQR(X1(Y) ^2 +X2(Y) ^2)
1410 RETURN
1420 END
1500 VTAB 5: PRINT "FAST FOURIER TRANSFORM"
1510 PRINT : PRINT "AUTHOR UNKNOWN"
1520 PRINT "DATE: 7-79"
1530 PRINT : PRINT : PRINT "THIS PROGRAM CALCULATES & PLOTS"
1540 PRINT "FAST FOURIER TRANSFORMATIONS"
1550 VTAB 20: PRINT "PRESS ESC TO END"
1560 PRINT : PRINT "<<PRESS SPACE BAR TO CONTINUE..>>"
1570 IF PEEK( -16384) = 27 THEN 1600
1580 CALL -756: IF PEEK( -16384) < >32 THEN 1500
1590 HOME : POKE -16368,0: RETURN
1600 HOME : END